<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

if(isset($_SESSION['lang']))
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../value/value_en.php";
} else if($lang == "VN") {
	include "../value/value_vn.php";
}
else {
	include "../value/value_kr.php";
}
include("sa_funcs.php");
$mthu=array();
$mthu[0]='<font color="red" ><b>'.$l_vday_chunhat.'</b></font>';
$mthu[1]=$l_vday_thuhai;
$mthu[2]=$l_vday_thuba;
$mthu[3]=$l_vday_thutu;
$mthu[4]=$l_vday_thunam;
$mthu[5]=$l_vday_thusau;
$mthu[6]='<font color="red" ><b>'.$l_vday_thubay.'</b></font>';
$mthu[7]='';

$_SESSION['thongbao_chamcong']="";
unset($_SESSION['searchload']);
unset($_SESSION['loadCheckTimes']);
if (isset($_REQUEST['datefrom']) && isset($_REQUEST['dateto']) && isset($_REQUEST['employeename'])) {
	include 'CheckTime.php';
	include '../operations/connection.php';
	$sql = sprintf("select em.IDEmployee as emid,
	em.FullName as emname,
	ct.id,
	ct.employeeID,
	upsuser.FullName as upname ,
	cruser.FullName as crname ,
	ct.employeeName,ct.time_work,
	ct.time_in,ct.time_out,
	ct.is_late,
	ct.is_comeback_early,
	ct.half_day_off,
	ct.all_day_off,
	ct.overtime,
	ct.note,
	ct.user_create,ct.createDate,
	ct.user_update,
	ct.update_date,ct.`status` as stct   
from sa_check_time ct left join employee em on ct.employeeID = em.EmployeeCode 
left join  employee upsuser on upsuser.IDEmployee = ct.user_update 
left join employee cruser on cruser.IDEmployee = ct.user_create 
where ct.`status`!=1 and '%s' <= ct.time_work 
and ct.time_work <= '%s' 
and em.FullName like '%s' order by ct.employeeID,ct.time_work asc",$_REQUEST['datefrom'],$_REQUEST['dateto'],'%'.$_REQUEST['employeename'].'%') ;
	$list = mysql_query($sql);
	$objects = array();
	$key = 0;
	$flagEmpty = true;
	?>
	<table style="width: 100%;" class="rf-dt" id="checktimes">
					<tr>
						<td class="rf-dt-shdr-c" width="2%">No.</td>
						<td class="rf-dt-shdr-c" width="10px"><input onclick="checkAll(this)" type="checkbox" /></td>
						<td class="rf-dt-shdr-c" width="15%"><?=$l_employee_name?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_code?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_thu?></td>
						<td class="rf-dt-shdr-c" width="10%"><?=$l_date?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_timecheckin?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_timecheckout?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_late?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_comebackearly?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_half_dayoff?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_all_dayoff?></td>
						<td class="rf-dt-shdr-c" width="5%"><?=$l_overtime?></td>
						<td class="rf-dt-shdr-c" width="10%"><?=$l_note?></td>
						<td class="rf-dt-shdr-c" width="8%"><?=$l_status?></td>
						<td class="rf-dt-shdr-c" width="13%"><?=$l_update_information?></td>
					</tr>
	
	<?php 
	$i=1;
	$temp="";
	while($row = mysql_fetch_array($list)){
		$flagEmpty = false;
		$object = new CheckTime();
		$object->Instance($row['id'],$row['employeeID'], $row['emname'], $row['time_work'], $row['time_in'], $row['time_out'], $row['is_late'], 
		$row['is_comeback_early'], $row['half_day_off'], $row['all_day_off'], $row['overtime'], $row['note']);
			if($row[user_update]==""){
				$object->setUpdateInfo($row['crname'],$row['createDate']);
			}else{
				$object->setUpdateInfo($row['upname'],$row['update_date']);
			}
			$object->setIs_status($row['stct']);
		$thu=getWday($row['time_work']);
		if($thu==6 || $thu==0){
			?>
			<tr style="background:#ccffcc;" >
			<?php 
		}else{
			?>
			<tr >
			<?php 
		}
		if($temp!=$object->employeeID){
			$temp=$object->employeeID;
			$i=1;
		}else{
			$i=$i+1;
		}
		
		echo '<td class="rf-dt-c" style="text-align:center;">';
		echo $i;
		echo '</td>';
		
		if($object->is_status==0){
			echo '<td class="rf-dt-c">';
			echo '<input title="checkCT" name="ctime['.$key.']" type="checkbox"/><input type="hidden" class="idupdate" name="vtime['.$key.']" value="'.$object->id.'"/>';
			echo '</td>';
								
			echo '<td class="rf-dt-c" style="color:blue"><span onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="updateCheckTime(this)">';
			echo $object->employeeName;
			echo '</span></td>';
	
			echo '<td class="rf-dt-c" style="color:blue;text-align:center;"><span onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="updateCheckTime(this)">';
			echo $object->employeeID;
			echo '</span></td>';
			
			echo '<td class="rf-dt-c" style="color:blue;text-align:center;"><span onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="updateCheckTime(this)">';
			echo $mthu[$thu];
			echo '</span></td>';
	
			echo '<td class="rf-dt-c" style="color:blue;text-align:center;"><span onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="updateCheckTime(this)">';
			echo $object->date;
			echo '</span><input type="hidden" class="dateupdate" value="'.$object->date.'" />';
			echo '</td>';
		}else{
			echo '<td class="rf-dt-c">';
			//echo '<input style="visibility: hidden;" title="checkCT" name="ctime['.$key.']" type="checkbox"/><input type="hidden" class="idupdate" name="vtime['.$key.']" value="'.$object->id.'"/>';
			echo '</td>';
								
			echo '<td class="rf-dt-c" >';
			echo $object->employeeName;
			echo '</td>';
	
			echo '<td class="rf-dt-c" style="text-align:center;">';
			echo $object->employeeID;
			echo '</td>';
			
			echo '<td class="rf-dt-c" style="text-align:center;">';
			echo $mthu[$thu];
			echo '</td>';
	
			echo '<td class="rf-dt-c" style="text-align:center;">';
			echo $object->date;
			echo '<input type="hidden" class="dateupdate" value="'.$object->date.'" />';
			echo '</td>';
		}
		

		echo '<td class="rf-dt-c" style="text-align:center;">';
		if($object->inTime != "0") echo $object->inTime;
		echo '<input type="hidden" class="inupdate" value="'.$object->inTime.'" />';
		echo '</td>';

		echo '<td class="rf-dt-c" style="text-align:center;">';
		if($object->outTime != "0") echo $object->outTime;
		echo '<input type="hidden" class="outupdate" value="'.$object->outTime.'" />';
		echo '</td>';

		if($object->late != "0") {
			echo '<td class="rf-dt-c" style="font-weight:bold;background:orange;text-align:center;">X</td>';
		}else{
			echo '<td class="rf-dt-c"></td>';
		}

		if($object->early != "0") {
			echo '<td class="rf-dt-c" style="font-weight:bold;background:yellow;text-align:center;">X</td>';
		}else{
			echo '<td class="rf-dt-c"></td>';
		}

		if($object->halfDayOff != "0") {
			echo '<td class="rf-dt-c" style="font-weight:bold;background:pink;text-align:center;">X</td>';
		}else{
			echo '<td class="rf-dt-c"></td>';
		}

		if($object->aDayOff != "0") {
			echo '<td class="rf-dt-c" style="font-weight:bold;background:red;text-align:center;">X</td>';
		}else{
			echo '<td class="rf-dt-c"></td>';
		}

		if($object->overtime != "0") {
			echo '<td class="rf-dt-c" style="font-weight:bold;background:green;text-align:center;">';
			for ($j=0;$j<$object->overtime;$j++){
				echo 'X';
			}
			echo '</td>';
		}else{
			echo '<td class="rf-dt-c"></td>';
		}

		echo '<td class="rf-dt-c" style="text-align:center;">';
		echo $object->note;
		echo '</td>';
		?>
		<td class="rf-dt-c" style="text-align:center;">
			<?php 
				if($object->is_status==0){
					echo $l_co_the_sua;
				}else if($object->is_status==2){
					echo $l_da_tinh_luong;
				}
			?>
		</td>
		<?php 
		?>
		<td class="rf-dt-c" style="text-align:center;">
			<?php echo $object->update_user."<br>".$object->update_time;?>
		</td>
		<?php 
		echo '</tr>';
		array_push($objects, $object);
		$key +=1;
	}
	if ($flagEmpty==true) {
		echo '<tr>';
		echo '<td class="rf-dt-c" colspan="13">';
		echo $_REQUEST['l_list_emplty'];
		echo '</tr>';
		echo '</tr>';
	}else{
		?>
		<tr>
			<td colspan="16">
				<div style="width:100%" id="showtb">
					<input type="hidden" id="viewthongbao" name="viewthongbao" value="<?php echo $_SESSION['thongbao_chamcong'];?>" />
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="15" align="center" style="padding: 10px">
				<input onclick="sendmail('<?=$_REQUEST['datefrom']?>','<?=$_REQUEST['dateto']?>','<?=$_REQUEST['employeename']?>');" type="button" value="<?php echo $l_sendmail;?>" id="btsendmail" name="btsendmail" class="btnupbg btnupload"/> 
			</td>
		</tr>
	
		<?php
		 
	}?>
	</table>
	<?php 
	$_SESSION['searchload'] = array('datefrom' => $_REQUEST['datefrom'] ,'dateto' => $_REQUEST['dateto'] ,'employeename' => $_REQUEST['employeename']);
	$_SESSION['loadCheckTimes'] = $objects;
	mysql_close($connection);
}
?>